home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / cpp.info-2 < prev    next >
Encoding:
Text File  |  1990-02-21  |  33.8 KB  |  925 lines

  1. Info file cpp.info, produced by Makeinfo, -*- Text -*- from input
  2. file cpp.texinfo.
  3.  
  4. This file documents the GNU C Preprocessor.
  5.  
  6. Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  7.  
  8. Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12. Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the entire resulting derived work is distributed under the terms
  15. of a permission notice identical to this one.
  16.  
  17. Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions.
  20.  
  21.  
  22. 
  23. File: cpp.info,  Node: Self-Reference,  Next: Argument Prescan,  Prev: Side Effects,  Up: Macro Pitfalls
  24.  
  25. Self-Referential Macros
  26. .......................
  27.  
  28.  A "self-referential" macro is one whose name appears in its definition.
  29. A special feature of ANSI Standard C is that the self-reference is
  30. not considered a macro call.  It is passed into the preprocessor
  31. output unchanged.
  32.  
  33. Let's consider an example:
  34.  
  35.      #define foo (4 + foo)
  36.  
  37. where `foo' is also a variable in your program.
  38.  
  39. Following the ordinary rules, each reference to `foo' will expand
  40. into `(4 + foo)'; then this will be rescanned and will expand into
  41. `(4 + (4 + foo))'; and so on until it causes a fatal error (memory
  42. full) in the preprocessor.
  43.  
  44. However, the special rule about self-reference cuts this process
  45. short after one step, at `(4 + foo)'.  Therefore, this macro
  46. definition has the possibly useful effect of causing the program to
  47. add 4 to the value of `foo' wherever `foo' is referred to.
  48.  
  49. In most cases, it is a bad idea to take advantage of this feature.  A
  50. person reading the program who sees that `foo' is a variable will not
  51. expect that it is a macro as well.  The reader will come across the
  52. identifier `foo' in the program and think its value should be that of
  53. the variable `foo', whereas in fact the value is four greater.
  54.  
  55. The special rule for self-reference applies also to "indirect"
  56. self-reference.  This is the case where a macro X expands to use a
  57. macro `y', and `y''s expansion refers to the macro `x'.  The
  58. resulting reference to `x' comes indirectly from the expansion of
  59. `x', so it is a self-reference and is not further expanded.  Thus,
  60. after
  61.  
  62.      #define x (4 + y)
  63.      #define y (2 * x)
  64.  
  65. `x' would expand into `(4 + (2 * x))'.  Clear?
  66.  
  67. But suppose `y' is used elsewhere, not from the definition of `x'. 
  68. Then the use of `x' in the expansion of `y' is not a self-reference
  69. because `x' is not ``in progress''.  So it does expand.  However, the
  70. expansion of `x' contains a reference to `y', and that is an indirect
  71. self-reference now because `y' is ``in progress''.  The result is
  72. that `y' expands to `(2 * (4 + y))'.
  73.  
  74. It is not clear that this behavior would ever be useful, but it is
  75. specified by the ANSI C standard, so you need to understand it.
  76.  
  77.  
  78. 
  79. File: cpp.info,  Node: Argument Prescan,  Next: Cascaded Macros,  Prev: Self-Reference,  Up: Macro Pitfalls
  80.  
  81. Separate Expansion of Macro Arguments
  82. .....................................
  83.  
  84.  We have explained that the expansion of a macro, including the
  85. substituted actual arguments, is scanned over again for macro calls
  86. to be expanded.
  87.  
  88. What really happens is more subtle: first each actual argument text
  89. is scanned separately for macro calls.  Then the results of this are
  90. substituted into the macro body to produce the macro expansion, and
  91. the macro expansion is scanned again for macros to expand.
  92.  
  93. The result is that the actual arguments are scanned *twice* to expand
  94. macro calls in them.
  95.  
  96. Most of the time, this has no effect.  If the actual argument
  97. contained any macro calls, they are expanded during the first scan. 
  98. The result therefore contains no macro calls, so the second scan does
  99. not change it.  If the actual argument were substituted as given,
  100. with no prescan, the single remaining scan would find the same macro
  101. calls and produce the same results.
  102.  
  103. You might expect the double scan to change the results when a
  104. self-referential macro is used in an actual argument of another macro
  105. (*note Self-Reference::.): the self-referential macro would be
  106. expanded once in the first scan, and a second time in the second
  107. scan.  But this is not what happens.  The self-references that do not
  108. expand in the first scan are marked so that they will not expand in
  109. the second scan either.
  110.  
  111. The prescan is not done when an argument is stringified or
  112. concatenated.  Thus,
  113.  
  114.      #define str(s) #s
  115.      #define foo 4
  116.      str (foo)
  117.  
  118. expands to `"foo"'.  Once more, prescan has been prevented from
  119. having any noticeable effect.
  120.  
  121. More precisely, stringification and concatenation use the argument as
  122. written, in un-prescanned form.  The same actual argument would be
  123. used in prescanned form if it is substituted elsewhere without
  124. stringification or concatenation.
  125.  
  126.      #define str(s) #s lose(s)
  127.      #define foo 4
  128.      str (foo)
  129.  
  130. expands to `"foo" lose(4)'.
  131.  
  132. You might now ask, ``Why mention the prescan, if it makes no
  133. difference?  And why not skip it and make the preprocessor faster?'' 
  134. The answer is that the prescan does make a difference in three
  135. special cases:
  136.  
  137.    * Nested calls to a macro.
  138.  
  139.    * Macros that call other macros that stringify or concatenate.
  140.  
  141.    * Macros whose expansions contain unshielded commas.
  142.  
  143. We say that "nested" calls to a macro occur when a macro's actual
  144. argument contains a call to that very macro.  For example, if `f' is
  145. a macro that expects one argument, `f (f (1))' is a nested pair of
  146. calls to `f'.  The desired expansion is made by expanding `f (1)' and
  147. substituting that into the definition of `f'.  The prescan causes the
  148. expected result to happen.  Without the prescan, `f (1)' itself would
  149. be substituted as an actual argument, and the inner use of `f' would
  150. appear during the main scan as an indirect self-reference and would
  151. not be expanded.  Here, the prescan cancels an undesirable side
  152. effect (in the medical, not computational, sense of the term) of the
  153. special rule for self-referential macros.
  154.  
  155. But prescan causes trouble in certain other cases of nested macro
  156. calls.  Here is an example:
  157.  
  158.      #define foo  a,b
  159.      #define bar(x) lose(x)
  160.      #define lose(x) (1 + (x))
  161.      
  162.      bar(foo)
  163.  
  164. We would like `bar(foo)' to turn into `(1 + (foo))', which would then
  165. turn into `(1 + (a,b))'.  But instead, `bar(foo)' expands into
  166. `lose(a,b)', and you get an error because `lose' requires a single
  167. argument.  In this case, the problem is easily solved by the same
  168. parentheses that ought to be used to prevent misnesting of arithmetic
  169. operations:
  170.  
  171.      #define foo (a,b)
  172.      #define bar(x) lose((x))
  173.  
  174. The problem is more serious when the operands of the macro are not
  175. expressions; for example, when they are statements.  Then parentheses
  176. are unacceptable because they would make for invalid C code:
  177.  
  178.      #define foo { int a, b; ... }
  179.  
  180. In GNU C you can shield the commas using the `({...})' construct
  181. which turns a compound statement into an expression:
  182.  
  183.      #define foo ({ int a, b; ... })
  184.  
  185. Or you can rewrite the macro definition to avoid such commas:
  186.  
  187.      #define foo { int a; int b; ... }
  188.  
  189. There is also one case where prescan is useful.  It is possible to
  190. use prescan to expand an argument and then stringify it--if you use
  191. two levels of macros.  Let's add a new macro `xstr' to the example
  192. shown above:
  193.  
  194.      #define xstr(s) str(s)
  195.      #define str(s) #s
  196.      #define foo 4
  197.      xstr (foo)
  198.  
  199. This expands into `"4"', not `"foo"'.  The reason for the difference
  200. is that the argument of `xstr' is expanded at prescan (because `xstr'
  201. does not specify stringification or concatenation of the argument). 
  202. The result of prescan then forms the actual argument for `str'. 
  203. `str' uses its argument without prescan because it performs
  204. stringification; but it cannot prevent or undo the prescanning
  205. already done by `xstr'.
  206.  
  207.  
  208. 
  209. File: cpp.info,  Node: Cascaded Macros,  Prev: Argument Prescan,  Up: Macro Pitfalls
  210.  
  211. Cascaded Use of Macros
  212. ......................
  213.  
  214.  A "cascade" of macros is when one macro's body contains a reference
  215. to another macro.  This is very common practice.  For example,
  216.  
  217.      #define BUFSIZE 1020
  218.      #define TABLESIZE BUFSIZE
  219.  
  220. This is not at all the same as defining `TABLESIZE' to be `1020'. 
  221. The `#define' for `TABLESIZE' uses exactly the body you specify--in
  222. this case, `BUFSIZE'--and does not check to see whether it too is the
  223. name of a macro.
  224.  
  225. It's only when you *use* `TABLESIZE' that the result of its expansion
  226. is checked for more macro names.
  227.  
  228. This makes a difference if you change the definition of `BUFSIZE' at
  229. some point in the source file.  `TABLESIZE', defined as shown, will
  230. always expand using the definition of `BUFSIZE' that is currently in
  231. effect:
  232.  
  233.      #define BUFSIZE 1020
  234.      #define TABLESIZE BUFSIZE
  235.      #undef BUFSIZE
  236.      #define BUFSIZE 37
  237.  
  238. Now `TABLESIZE' expands (in two stages) to `37'.
  239.  
  240.  
  241. 
  242. File: cpp.info,  Node: Conditionals,  Next: Combining Sources,  Prev: Macros,  Up: Top
  243.  
  244. Conditionals
  245. ============
  246.  
  247. In a macro processor, a "conditional" is a command that allows a part
  248. of the program to be ignored during compilation, on some conditions. 
  249. In the C preprocessor, a conditional can test either an arithmetic
  250. expression or whether a name is defined as a macro.
  251.  
  252. A conditional in the C preprocessor resembles in some ways an `if'
  253. statement in C, but it is important to understand the difference
  254. between them.  The condition in an `if' statement is tested during
  255. the execution of your program.  Its purpose is to allow your program
  256. to behave differently from run to run, depending on the data it is
  257. operating on.  The condition in a preprocessor conditional command is
  258. tested when your program is compiled.  Its purpose is to allow
  259. different code to be included in the program depending on the
  260. situation at the time of compilation.
  261.  
  262. * Menu:
  263.  
  264. * Uses: Conditional Uses.       What conditionals are for.
  265. * Syntax: Conditional Syntax.   How conditionals are written.
  266. * Deletion: Deleted Code.       Making code into a comment.
  267. * Macros: Conditionals-Macros.  Why conditionals are used with macros.
  268. * Errors: #error Command.       Detecting inconsistent compilation parameters.
  269.  
  270.  
  271. 
  272. File: cpp.info,  Node: Conditional Uses,  Next: Conditional Syntax,  Prev: Conditionals,  Up: Conditionals
  273.  
  274. Why Conditionals are Used
  275. -------------------------
  276.  
  277. Generally there are three kinds of reason to use a conditional.
  278.  
  279.    * A program may need to use different code depending on the
  280.      machine or operating system it is to run on.  In some cases the
  281.      code for one operating system may be erroneous on another
  282.      operating system; for example, it might refer to library
  283.      routines that do not exist on the other system.  When this
  284.      happens, it is not enough to avoid executing the invalid code:
  285.      merely having it in the program makes it impossible to link the
  286.      program and run it.  With a preprocessor conditional, the
  287.      offending code can be effectively excised from the program when
  288.      it is not valid.
  289.  
  290.    * You may want to be able to compile the same source file into two
  291.      different programs.  Sometimes the difference between the
  292.      programs is that one makes frequent time-consuming consistency
  293.      checks on its intermediate data while the other does not.
  294.  
  295.    * A conditional whose condition is always false is a good way to
  296.      exclude code from the program but keep it as a sort of comment
  297.      for future reference.
  298.  
  299. Most simple programs that are intended to run on only one machine
  300. will not need to use preprocessor conditionals.
  301.  
  302.  
  303. 
  304. File: cpp.info,  Node: Conditional Syntax,  Next: Deleted Code,  Prev: Conditional Uses,  Up: Conditionals
  305.  
  306. Syntax of Conditionals
  307. ----------------------
  308.  
  309. A conditional in the C preprocessor begins with a "conditional
  310. command": `#if', `#ifdef' or `#ifndef'.  *Note Conditionals-Macros::,
  311. for info on `#ifdef' and `#ifndef'; only `#if' is explained here.
  312.  
  313. * Menu:
  314.  
  315. * If: #if Command.     Basic conditionals using `#if' and `#endif'.
  316. * Else: #else Command. Including some text if the condition fails.
  317. * Elif: #elif Command. Testing several alternative possibilities.
  318.  
  319.  
  320. 
  321. File: cpp.info,  Node: #if Command,  Next: #else Command,  Prev: Conditional Syntax,  Up: Conditional Syntax
  322.  
  323. The `#if' Command
  324. .................
  325.  
  326.  The `#if' command in its simplest form consists of
  327.  
  328.      #if EXPRESSION
  329.      CONTROLLED TEXT
  330.      #endif /* EXPRESSION */
  331.  
  332. The comment following the `#endif' is not required, but it is a good
  333. practice because it helps people match the `#endif' to the
  334. corresponding `#if'.  Such comments should always be used, except in
  335. short conditionals that are not nested.  In fact, you can put
  336. anything at all after the `#endif' and it will be ignored by the GNU
  337. C preprocessor, but only comments are acceptable in ANSI Standard C.
  338.  
  339. EXPRESSION is a C expression of integer type, subject to stringent
  340. restrictions.  It may contain
  341.  
  342.    * Integer constants, which are all regarded as `long' or `unsigned
  343.      long'.
  344.  
  345.    * Character constants, which are interpreted according to the
  346.      character set and conventions of the machine and operating
  347.      system on which the preprocessor is running.  The GNU C
  348.      preprocessor uses the C data type `char' for these character
  349.      constants; therefore, whether some character codes are negative
  350.      is determined by the C compiler used to compile the
  351.      preprocessor.  If it treats `char' as signed, then character
  352.      codes large enough to set the sign bit will be considered
  353.      negative; otherwise, no character code is considered negative.
  354.  
  355.    * Arithmetic operators for addition, subtraction, multiplication,
  356.      division, bitwise operations, shifts, comparisons, and `&&' and
  357.      `||'.
  358.  
  359.    * Identifiers that are not macros, which are all treated as zero(!).
  360.  
  361.    * Macro calls.  All macro calls in the expression are expanded
  362.      before actual computation of the expression's value begins.
  363.  
  364. Note that `sizeof' operators and `enum'-type values are not allowed. 
  365. `enum'-type values, like all other identifiers that are not taken as
  366. macro calls and expanded, are treated as zero.
  367.  
  368. The text inside of a conditional can include preprocessor commands. 
  369. Then the commands inside the conditional are obeyed only if that
  370. branch of the conditional succeeds.  The text can also contain other
  371. conditional groups.  However, the `#if''s and `#endif''s must balance.
  372.  
  373.  
  374. 
  375. File: cpp.info,  Node: #else Command,  Next: #elif Command,  Prev: #if Command,  Up: Conditional Syntax
  376.  
  377. The `#else' Command
  378. ...................
  379.  
  380.  The `#else' command can be added to a conditional to provide
  381. alternative text to be used if the condition is false.  This looks like
  382.  
  383.      #if EXPRESSION
  384.      TEXT-IF-TRUE
  385.      #else /* Not EXPRESSION */
  386.      TEXT-IF-FALSE
  387.      #endif /* Not EXPRESSION */
  388.  
  389. If EXPRESSION is nonzero, and the TEXT-IF-TRUE is considered
  390. included, then `#else' acts like a failing conditional and the
  391. TEXT-IF-FALSE is ignored.  Contrariwise, if the `#if' conditional
  392. fails, the TEXT-IF-FALSE is considered included.
  393.  
  394.  
  395. 
  396. File: cpp.info,  Node: #elif Command,  Prev: #else Command,  Up: Conditional Syntax
  397.  
  398. The `#elif' Command
  399. ...................
  400.  
  401.  One common case of nested conditionals is used to check for more than
  402. two possible alternatives.  For example, you might have
  403.  
  404.      #if X == 1
  405.      ...
  406.      #else /* X != 1 */
  407.      #if X == 2
  408.      ...
  409.      #else /* X != 2 */
  410.      ...
  411.      #endif /* X != 2 */
  412.      #endif /* X != 1 */
  413.  
  414. Another conditional command, `#elif', allows this to be abbreviated
  415. as follows:
  416.  
  417.      #if X == 1
  418.      ...
  419.      #elif X == 2
  420.      ...
  421.      #else /* X != 2 and X != 1*/
  422.      ...
  423.      #endif /* X != 2 and X != 1*/
  424.  
  425. `#elif' stands for ``else if''.  Like `#else', it goes in the middle
  426. of a `#if'-`#endif' pair and subdivides it; it does not require a
  427. matching `#endif' of its own.  Like `#if', the `#elif' command
  428. includes an expression to be tested.
  429.  
  430. The text following the `#elif' is processed only if the original
  431. `#if'-condition failed and the `#elif' condition succeeeds.  More
  432. than one `#elif' can go in the same `#if'-`#endif' group.  Then the
  433. text after each `#elif' is processed only if the `#elif' condition
  434. succeeds after the original `#if' and any previous `#elif''s within
  435. it have failed.  `#else' is equivalent to `#elif 1', and `#else' is
  436. allowed after any number of `#elif''s, but `#elif' may not follow a
  437. `#else'.
  438.  
  439.  
  440. 
  441. File: cpp.info,  Node: Deleted Code,  Next: Conditionals-Macros,  Prev: Conditional Syntax,  Up: Conditionals
  442.  
  443. Keeping Deleted Code for Future Reference
  444. -----------------------------------------
  445.  
  446. If you replace or delete a part of the program but want to keep the
  447. old code around as a comment for future reference, the easy way to do
  448. this is to put `#if 0' before it and `#endif' after it.
  449.  
  450. This works even if the code being turned off contains conditionals,
  451. but they must be entire conditionals (balanced `#if' and `#endif').
  452.  
  453.  
  454. 
  455. File: cpp.info,  Node: Conditionals-Macros,  Next: #error Command,  Prev: Deleted Code,  Up: Conditionals
  456.  
  457. Conditionals and Macros
  458. -----------------------
  459.  
  460. Conditionals are rarely useful except in connection with macros.  A
  461. `#if' command whose expression uses no macros is equivalent to `#if
  462. 1' or `#if 0'; you might as well determine which one, by computing
  463. the value of the expression yourself, and then simplify the program. 
  464. But when the expression uses macros, its value can vary from
  465. compilation to compilation.
  466.  
  467. For example, here is a conditional that tests the expression `BUFSIZE
  468. == 1020', where `BUFSIZE' must be a macro.
  469.  
  470.      #if BUFSIZE == 1020
  471.        printf ("Large buffers!\n");
  472.      #endif /* BUFSIZE is large */
  473.  
  474. The special operator `defined' may be used in `#if' expressions to
  475. test whether a certain name is defined as a macro.  Either `defined
  476. NAME' or `defined (NAME)' is an expression whose value is 1 if NAME
  477. is defined as macro at the current point in the program, and 0
  478. otherwise.  For the `defined' operator it makes no difference what
  479. the definition of the macro is; all that matters is whether there is
  480. a definition.  Thus, for example,
  481.  
  482.      #if defined (vax) || defined (ns16000)
  483.  
  484. would include the following code if either of the names `vax' and
  485. `ns16000' is defined as a macro.
  486.  
  487. If a macro is defined and later undefined with `#undef', subsequent
  488. use of the `defined' operator will return 0, because the name is no
  489. longer defined.  If the macro is defined again with another
  490. `#define', `defined' will recommence returning 1.
  491.  
  492. Conditionals that test just the definedness of one name are very
  493. common, so there are two special short conditional commands for this
  494. case.  They are
  495.  
  496. `#ifdef NAME'
  497.      is equivalent to `#if defined (NAME)'.
  498.  
  499. `#ifndef NAME'
  500.      is equivalent to `#if ! defined (NAME)'.
  501.  
  502. Macro definitions can vary between compilations for several reasons.
  503.  
  504.    * Some macros are predefined on each kind of machine.  For
  505.      example, on a Vax, the name `vax' is a predefined macro.  On
  506.      other machines, it would not be defined.
  507.  
  508.    * Many more macros are defined by system header files.  Different
  509.      systems and machines define different macros, or give them
  510.      different values.  It is useful to test these macros with
  511.      conditionals to avoid using a system feature on a machine where
  512.      it is not implemented.
  513.  
  514.    * Macros are a common way of allowing users to customize a program
  515.      for different machines or applications.  For example, the macro
  516.      `BUFSIZE' might be defined in a configuration file for your
  517.      program that is included as a header file in each source file. 
  518.      You would use `BUFSIZE' in a preprocessor conditional in order
  519.      to generate different code depending on the chosen configuration.
  520.  
  521.    * Macros can be defined or undefined with `-D' and `-U' command
  522.      options when you compile the program.  You can arrange to
  523.      compile the same source file into two different programs by
  524.      choosing a macro name to specify which program you want, writing
  525.      conditionals to test whether or how this macro is defined, and
  526.      then controlling the state of the macro with compiler command
  527.      options.  *Note Invocation::.
  528.  
  529.  
  530. 
  531. File: cpp.info,  Node: #error Command,  Prev: Conditionals-Macros,  Up: Conditionals
  532.  
  533. The `#error' Command
  534. --------------------
  535.  
  536. The command `#error' causes the preprocessor to report a fatal error.
  537. The rest of the line that follows `#error' is used as the error
  538. message.
  539.  
  540. You would use `#error' inside of a conditional that detects a
  541. combination of parameters which you know the program does not
  542. properly support.  For example, if you know that the program will not
  543. run properly on a Vax, you might write
  544.  
  545.      #ifdef vax
  546.      #error Won't work on Vaxen.  See comments at get_last_object.
  547.      #endif
  548.  
  549. *Note Nonstandard Predefined::, for why this works.
  550.  
  551. If you have several configuration parameters that must be set up by
  552. the installation in a consistent way, you can use conditionals to
  553. detect an inconsistency and report it with `#error'.  For example,
  554.  
  555.      #if HASH_TABLE_SIZE % 2 == 0 || HASH_TABLE_SIZE % 3 == 0 \
  556.          || HASH_TABLE_SIZE % 5 == 0
  557.      #error HASH_TABLE_SIZE should not be divisible by a small prime
  558.      #endif
  559.  
  560.  
  561. 
  562. File: cpp.info,  Node: Combining Sources,  Next: Other Commands,  Prev: Conditionals,  Up: Top
  563.  
  564. Combining Source Files
  565. ======================
  566.  
  567. One of the jobs of the C preprocessor is to inform the C compiler of
  568. where each line of C code came from: which source file and which line
  569. number.
  570.  
  571. C code can come from multiple source files if you use `#include';
  572. both `#include' and the use of conditionals and macros can cause the
  573. line number of a line in the preprocessor output to be different from
  574. the line's number in the original source file.  You will appreciate
  575. the value of making both the C compiler (in error messages) and
  576. symbolic debuggers such as GDB use the line numbers in your source
  577. file.
  578.  
  579. The C preprocessor builds on this feature by offering a command by
  580. which you can control the feature explicitly.  This is useful when a
  581. file for input to the C preprocessor is the output from another
  582. program such as the `bison' parser generator, which operates on
  583. another file that is the true source file.  Parts of the output from
  584. `bison' are generated from scratch, other parts come from a standard
  585. parser file.  The rest are copied nearly verbatim from the source
  586. file, but their line numbers in the `bison' output are not the same
  587. as their original line numbers.  Naturally you would like compiler
  588. error messages and symbolic debuggers to know the original source
  589. file and line number of each line in the `bison' output.
  590.  
  591. `bison' arranges this by writing `#line' commands into the output
  592. file.  `#line' is a command that specifies the original line number
  593. and source file name for subsequent input in the current preprocessor
  594. input file.  `#line' has three variants:
  595.  
  596. `#line LINENUM'
  597.      Here LINENUM is a decimal integer constant.  This specifies that
  598.      the line number of the following line of input, in its original
  599.      source file, was LINENUM.
  600.  
  601. `#line LINENUM FILENAME'
  602.      Here LINENUM is a decimal integer constant and FILENAME is a
  603.      string constant.  This specifies that the following line of
  604.      input came originally from source file FILENAME and its line
  605.      number there was LINENUM.  Keep in mind that FILENAME is not
  606.      just a file name; it is surrounded by doublequote characters so
  607.      that it looks like a string constant.
  608.  
  609. `#line ANYTHING ELSE'
  610.      ANYTHING ELSE is checked for macro calls, which are expanded. 
  611.      The result should be a decimal integer constant followed
  612.      optionally by a string constant, as described above.
  613.  
  614. `#line' commands alter the results of the `__FILE__' and `__LINE__'
  615. predefined macros from that point on.  *Note Standard Predefined::.
  616.  
  617.  
  618. 
  619. File: cpp.info,  Node: Other Commands,  Next: Output,  Prev: Combining Sources,  Up: Top
  620.  
  621. Miscellaneous Preprocessor Commands
  622. ===================================
  623.  
  624. This section describes three additional preprocessor commands.  They
  625. are not very useful, but are mentioned for completeness.
  626.  
  627. The "null command" consists of a `#' followed by a Newline, with only
  628. whitespace (including comments) in between.  A null command is
  629. understood as a preprocessor command but has no effect on the
  630. preprocessor output.  The primary significance of the existence of
  631. the null command is that an input line consisting of just a `#' will
  632. produce no output, rather than a line of output containing just a
  633. `#'.  Supposedly some old C programs contain such lines.
  634.  
  635. The `#pragma' command is specified in the ANSI standard to have an
  636. arbitrary implementation-defined effect.  In the GNU C preprocessor,
  637. `#pragma' commands are ignored, except for `#pragma once' (*note
  638. Once-Only::.).
  639.  
  640. The `#ident' command is supported for compatibility with certain
  641. other systems.  It is followed by a line of text.  On certain
  642. systems, the text is copied into a special place in the object file;
  643. on most systems, the text is ignored and this directive has no effect.
  644.  
  645.  
  646. 
  647. File: cpp.info,  Node: Output,  Next: Invocation,  Prev: Other Commands,  Up: Top
  648.  
  649. C Preprocessor Output
  650. =====================
  651.  
  652. The output from the C preprocessor looks much like the input, except
  653. that all preprocessor command lines have been replaced with blank
  654. lines and all comments with spaces.  Whitespace within a line is not
  655. altered; however, a space is inserted after the expansions of most
  656. macro calls.
  657.  
  658. Source file name and line number information is conveyed by lines of
  659. the form
  660.  
  661.      # LINENUM FILENAME FLAG
  662.  
  663. which are inserted as needed into the middle of the input (but never
  664. within a string or character constant).  Such a line means that the
  665. following line originated in file FILENAME at line LINENUM.
  666.  
  667. The third field, FLAG, may be a number, or may be absent.  It is `1'
  668. for the beginning of a new source file, and `2' for return to an old
  669. source file at the end of an included file.  It is absent otherwise.
  670.  
  671.  
  672. 
  673. File: cpp.info,  Node: Invocation,  Next: Concept Index,  Prev: Output,  Up: Top
  674.  
  675. Invoking the C Preprocessor
  676. ===========================
  677.  
  678. Most often when you use the C preprocessor you will not have to
  679. invoke it explicitly: the C compiler will do so automatically. 
  680. However, the preprocessor is sometimes useful individually.
  681.  
  682. The C preprocessor expects two file names as arguments, INFILE and
  683. OUTFILE.  The preprocessor reads INFILE together with any other files
  684. it specifies with `#include'.  All the output generated by the
  685. combined input files is written in OUTFILE.
  686.  
  687. Either INFILE or OUTFILE may be `-', which as INFILE means to read
  688. from standard input and as OUTFILE means to write to standard output.
  689. Also, if OUTFILE or both file names are omitted, the standard output
  690. and standard input are used for the omitted file names.
  691.  
  692. Here is a table of command options accepted by the C preprocessor. 
  693. Most of them can also be given when compiling a C program; they are
  694. passed along automatically to the preprocessor when it is invoked by
  695. the compiler.
  696.  
  697. `-P'
  698.      Inhibit generation of `#'-lines with line-number information in
  699.      the output from the preprocessor (*note Output::.).  This might
  700.      be useful when running the preprocessor on something that is not
  701.      C code and will be sent to a program which might be confused by
  702.      the `#'-lines
  703.  
  704. `-C'
  705.      Do not discard comments: pass them through to the output file. 
  706.      Comments appearing in arguments of a macro call will be copied
  707.      to the output before the expansion of the macro call.
  708.  
  709. `-trigraphs'
  710.      Process ANSI standard trigraph sequences.  These are
  711.      three-character sequences, all starting with `??', that are
  712.      defined by ANSI C to stand for single characters.  For example,
  713.      `??/' stands for `\', so `'??/n'' is a character constant for a
  714.      newline.  Strictly speaking, the GNU C preprocessor does not
  715.      support all programs in ANSI Standard C unless `-trigraphs' is
  716.      used, but if you ever notice the difference it will be with
  717.      relief.
  718.  
  719.      You don't want to know any more about trigraphs.
  720.  
  721. `-pedantic'
  722.      Issue warnings required by the ANSI C standard in certain cases
  723.      such as when text other than a comment follows `#else' or
  724.      `#endif'.
  725.  
  726. `-I DIRECTORY'
  727.      Add the directory DIRECTORY to the end of the list of
  728.      directories to be searched for header files (*note Include
  729.      Syntax::.).  This can be used to override a system header file,
  730.      substituting your own version, since these directories are
  731.      searched before the system header file directories.  If you use
  732.      more than one `-I' option, the directories are scanned in
  733.      left-to-right order; the standard system directories come after.
  734.  
  735. `-I-'
  736.      Any directories specified with `-I' options before the `-I-'
  737.      option are searched only for the case of `#include "FILE"'; they
  738.      are not searched for `#include <FILE>'.
  739.  
  740.      If additional directories are specified with `-I' options after
  741.      the `-I-', these directories are searched for all `#include'
  742.      directives.
  743.  
  744.      In addition, the `-I-' option inhibits the use of the current
  745.      directory as the first search directory for `#include "FILE"'. 
  746.      Therefore, the current directory is searched only if it is
  747.      requested explicitly with `-I.'.  Specifying both `-I-' and
  748.      `-I.' allows you to control precisely which directories are
  749.      searched before the current one and which are searched after.
  750.  
  751. `-nostdinc'
  752.      Do not search the standard system directories for header files. 
  753.      Only the directories you have specified with `-I' options (and
  754.      the current directory, if appropriate) are searched.
  755.  
  756. `-D NAME'
  757.      Predefine NAME as a macro, with definition `1'.
  758.  
  759. `-D NAME=DEFINITION'
  760.      Predefine NAME as a macro, with definition DEFINITION.  There
  761.      are no restrictions on the contents of DEFINITION, but if you
  762.      are invoking the preprocessor from a shell or shell-like program
  763.      you may need to use the shell's quoting syntax to protect
  764.      characters such as spaces that have a meaning in the shell syntax.
  765.  
  766. `-U NAME'
  767.      Do not predefine NAME.  If both `-U' and `-D' are specified for
  768.      one name, the `-U' beats the `-D' and the name is not predefined.
  769.  
  770. `-undef'
  771.      Do not predefine any nonstandard macros.
  772.  
  773. `-d'
  774.      Instead of outputting the result of preprocessing, output a list
  775.      of `#define' commands for all the macros defined during the
  776.      execution of the preprocessor.
  777.  
  778. `-M'
  779.      Instead of outputting the result of preprocessing, output a rule
  780.      suitable for `make' describing the dependencies of the main
  781.      source file.  The preprocessor outputs one `make' rule
  782.      containing the object file name for that source file, a colon,
  783.      and the names of all the included files.  If there are many
  784.      included files then the rule is split into several lines using
  785.      `\'-newline.
  786.  
  787.      This feature is used in automatic updating of makefiles.
  788.  
  789. `-MM'
  790.      Like `-M' but mention only the files included with `#include
  791.      "FILE"'.  System header files included with `#include <FILE>'
  792.      are omitted.
  793.  
  794. `-i FILE'
  795.      Process FILE as input, discarding the resulting output, before
  796.      processing the regular input file.  Because the output generated
  797.      from FILE is discarded, the only effect of `-i FILE' is to make
  798.      the macros defined in FILE available for use in the main input.
  799.  
  800.  
  801. 
  802. File: cpp.info,  Node: Concept Index,  Next: Index,  Prev: Invocation,  Up: Top
  803.  
  804. Concept Index
  805. *************
  806.  
  807. * Menu:
  808.  
  809. * cascaded macros: Cascaded Macros.
  810. * commands: Commands.
  811. * concatenation: Concatenation.
  812. * conditionals: Conditionals.
  813. * header file: Header Files.
  814. * line control: Combining Sources.
  815. * macro body uses macro: Cascaded Macros.
  816. * null command: Other Commands.
  817. * options: Invocation.
  818. * output format: Output.
  819. * predefined macros: Predefined.
  820. * preprocessor commands: Commands.
  821. * redefining macros: Redefining.
  822. * repeated inclusion: Once-Only.
  823. * self-reference: Self-Reference.
  824. * semicolons (after macro calls): Swallow Semicolon.
  825. * side effects (in macro arguments): Side Effects.
  826. * stringification: Stringification.
  827. * undefining macros: Undefining.
  828. * unsafe macros: Side Effects.
  829.  
  830.  
  831.  
  832. 
  833. File: cpp.info,  Node: Index,  Prev: Concept Index,  Up: Top
  834.  
  835. Index of Commands, Macros and Options
  836. *************************************
  837.  
  838. * Menu:
  839.  
  840. * #elif: #elif Command.
  841. * #else: #else Command.
  842. * #error: #error Command.
  843. * #ident: Other Commands.
  844. * #if: Conditional Syntax.
  845. * #ifdef: Conditionals-Macros.
  846. * #ifndef: Conditionals-Macros.
  847. * #include: Include Syntax.
  848. * #line: Combining Sources.
  849. * #pragma: Other Commands.
  850. * -C: Invocation.
  851. * -D: Invocation.
  852. * -I: Invocation.
  853. * -M: Invocation.
  854. * -MM: Invocation.
  855. * -P: Invocation.
  856. * -U: Invocation.
  857. * -d: Invocation.
  858. * -i: Invocation.
  859. * -pedantic: Invocation.
  860. * -trigraphs: Invocation.
  861. * -undef: Invocation.
  862. * BSD: Nonstandard Predefined.
  863. * M68020: Nonstandard Predefined.
  864. * __BASE_FILE__: Standard Predefined.
  865. * __DATE__: Standard Predefined.
  866. * __FILE__: Standard Predefined.
  867. * __LINE__: Standard Predefined.
  868. * __STDC__: Standard Predefined.
  869. * __TIME__: Standard Predefined.
  870. * defined: Conditionals-Macros.
  871. * m68k: Nonstandard Predefined.
  872. * mc68000: Nonstandard Predefined.
  873. * ns32000: Nonstandard Predefined.
  874. * pyr: Nonstandard Predefined.
  875. * sequent: Nonstandard Predefined.
  876. * sun: Nonstandard Predefined.
  877. * system header files: Header Uses.
  878. * unix: Nonstandard Predefined.
  879. * vax: Nonstandard Predefined.
  880.  
  881.  
  882.  
  883. Tag Table:
  884. Node: Top750
  885. Node: Global Actions3306
  886. Node: Commands5811
  887. Node: Header Files7416
  888. Node: Header Uses7992
  889. Node: Include Syntax9379
  890. Node: Include Operation12392
  891. Node: Once-Only14058
  892. Node: Macros15869
  893. Node: Simple Macros16781
  894. Node: Argument Macros19828
  895. Node: Predefined24918
  896. Node: Standard Predefined25346
  897. Node: Nonstandard Predefined29551
  898. Node: Stringification32833
  899. Node: Concatenation35672
  900. Node: Undefining38930
  901. Node: Redefining39952
  902. Node: Macro Pitfalls41238
  903. Node: Misnesting42281
  904. Node: Macro Parentheses43289
  905. Node: Swallow Semicolon45144
  906. Node: Side Effects47032
  907. Node: Self-Reference48718
  908. Node: Argument Prescan50967
  909. Node: Cascaded Macros55931
  910. Node: Conditionals56952
  911. Node: Conditional Uses58240
  912. Node: Conditional Syntax59627
  913. Node: #if Command60196
  914. Node: #else Command62447
  915. Node: #elif Command63094
  916. Node: Deleted Code64437
  917. Node: Conditionals-Macros64968
  918. Node: #error Command68190
  919. Node: Combining Sources69234
  920. Node: Other Commands71848
  921. Node: Output73081
  922. Node: Invocation74012
  923. Node: Concept Index79436
  924. Node: Index80238
  925.